import { Context, Schema } from 'koishi'

export const name = 'private-forward'

export interface Config {
  targetUserId: string
}

export const Config: Schema<Config> = Schema.intersect([

  Schema.object({
    targetUserId: Schema.string()
      .default("1830540513")
      .description("目标QQ")
  })

])

export function apply(ctx: Context, config: Config) {
  // write your plugin here

  ctx.on('message', async ( session ) => {
    if ( session.guildId !== undefined ) return;

    if ( session.userId === session.bot.selfId ) return;

    let msg = '收到私聊消息\n';
    msg += `\tqq号 = ${session.userId}\n`;
    msg += `\tqq名 = ${session.username}\n`;
    msg += `\t内容 = ${session.content}\n`;

    await session.bot.sendPrivateMessage(
      config.targetUserId,
      msg
    )

  })

}
